package support.implement.hibernate;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import support.dao.BookDao;
import support.domain.Book;

/**
 * 
 * @author Wangpeihu
 * @team [Never give up]
 * @since JDK1.6(建议)
 * @date 2010-2-9
 */
public class Test {
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext(
				"support/implement/hibernate/applicationContext.xml");
		BookDao bookDao = (BookDao) context.getBean("bookDao");

		/***************************************************
		 * Test save...
		 ***************************************************/

		double i = Math.random() * 10000;
		int j = (int) i;
		Book book1 = new Book(j, "Ruby:" + j, i);
		bookDao.save(book1);

		/***************************************************
		 * Test delete...
		 ***************************************************/
//		Book book2 = new Book();
//		book2.setId(705);
//		bookDao.delete(book2);

		/***************************************************
		 * Test update...
		 ***************************************************/
//		Book book3 = new Book();
//		book3.setId(2);
//		book3.setName("after update..");// 更新的数据
//		book3.setPrice(179.25); // 更新的数据
//		bookDao.update(book3);

		/***************************************************
		 * Test findBookByPrice...
		 ***************************************************/
//		List<Book> books1 = bookDao.findBookByPrice(0.1, 999999.99);
//		for (Book b : books1) {
//			System.out.println(b.getName());
//		}

		/***************************************************
		 * Test findBookByPrice...
		 ***************************************************/
		List<Book> books3 = bookDao.findAllBook();
		for (Book b3 : books3) {
			System.out.println(b3.getName());
		}

		
		
		
		
	}
}
